package com.example.aopdemo.AOP;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class UserAspect {
    @Pointcut("execution(* com.example.aopdemo.controller.UserController.*(..))")
    public void pointcut(){

    }
    @Before("pointcut()")
    public void beforeAdvice(){
        System.out.println("前置通知");
    }
    @After("pointcut()")
    public void afterAdvice(){
        System.out.println("后置通知");
    }

    @Around("pointcut()")
    public Object arondAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("进入环绕通知");
        Object object = null;
        object = joinPoint.proceed();
        System.out.println("退出环绕通知");
        return object;
    }
    @AfterReturning("pointcut()")
    public void afterReturning(){
        System.out.println("执行 return 之前通知");
    }

    @AfterThrowing("pointcut()")
    public void afterThrow(){
        System.out.println("抛出异常通知");
    }
}
